#!usr/bin/node

const http = require('https'),
      cheerio = require('cheerio'),
      log = console.log,
      baseURL = 'https://ke.segmentfault.com/',
      address = baseURL + 'free';

http.get(address,(res) => {
  console.log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
  console.log(res.headers);
  
  let html = "",$ = '';

  res.on('data',chunk => {
  html += chunk;
  });
  res.on('end',() => {
  $ = cheerio.load(html);
  $('body').find('.card-title>a').each(function(){
      const courseName = $(this).html(),
            courseUrl = $(this).attr('href');
      log('课程名称：',courseName);
      log('课程地址：',courseUrl);
    })
  })
})
